/**
 * 
 */
package net.entelijan.cobean.bind.impl;

import java.util.Collection;

import net.entelijan.cobean.bind.IBeanProperty;

class PlainBeanPropertyVariante implements IBeanProperty {

    private Object bean;

    public PlainBeanPropertyVariante(Object bean) {
        super();
        this.bean = bean;
    }

    public Object getValue() {
        return this.bean;
    }

    public void setValue(Object obj) {
        this.bean = obj;
    }

    public Object createPlaceholder() {
        if (this.bean == null) {
            throw new IllegalStateException("Cannot create placeholder");
        }
        try {
            return this.bean.getClass().newInstance();
        } catch (Exception e) {
            throw new IllegalStateException("Cannot createplaceholder. " + e.getMessage(), e);
        }
    }

    @Override
    public String toString() {
        return "BeanProperty(" + this.bean + ")";
    }

    @Override
    public String getPropertyName() {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isCollection() {
        return this.bean instanceof Collection<?>;
    }

    @Override
    public Object getBean() {
        throw new IllegalStateException("'" + getClass().getName() + "' does not support getBean()");
    }
}